﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 剧情设计器2._0
{
    [Serializable]
    public class Plot
    {
        //剧情的名称
        public string name = "";
        //剧情中包含的事件列表
        public List<Event> events = new List<Event>();

        //剧情的开始时间
        public int time_offset = 0;
        public override int GetHashCode()
        {
            int code = name.GetHashCode();
            foreach (Event @event in events)
                code += @event.GetHashCode();
            return code;
        }

        public int getTime()
        {
            int time = 0;
            foreach(Event @event in events)
            {
                time += @event.getTime();
            }
            time += time_offset;
            if (time != 0)
                return time;
            else return 1;
        }

        public void draw(Graphics g, int x, int y)
        {
            const int h = 88;
            int w = 0;
            for (int i = 0; i < events.Count; i++)
                w += events[i].getW();
            w += 2;
            int textHeight = 10;
            Pen pen = new Pen(Color.Green);

            g.DrawRectangle(pen, x, y, w, h);
            g.DrawString(name, new Font("微软雅黑", textHeight), pen.Brush, new PointF(x + 2, y + 1));
            int sum_w = 2;
            for(int i = 0; i < events.Count; i++)
            {
                events[i].draw(g, x + sum_w, y + 18);
                sum_w += events[i].getW();
            }
        }

        public int getW()
        {
            int sum_w = 2;
            for (int i = 0; i < events.Count; i++)
            {
                sum_w += events[i].getW();
            }
            return sum_w + 2 + time_offset * (112 + 6);
        }
    }
}
